from  appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

class CommonDriver:
    def get_driver(self):
        desc={
            'platformName':'Android',
            'platformVersion':'7',
            'appPackage':'com.dangdang.buy2',
            'appActivity':'com.dangdang.buy2.StartupActivity',
            'noReset':False,
            'unicodeKeyboard':True,
            'udid':'127.0.0.1:21513',
        }

        command_executor_url='http://127.0.0.1:4723/wd/hub'

        driver=webdriver.Remote(command_executor=command_executor_url,desired_capabilities=desc)

        driver.implicitly_wait(10)
        print('连接成功')
        return driver

if __name__ == '__main__':
    driver=CommonDriver().get_driver()
    driver.find_element(AppiumBy.XPATH,
                        '//android.widget.TextView[@resource-id="com.dangdang.buy2:id/tv_sure"]').click()
    driver.find_element(AppiumBy.XPATH,
                        '//android.widget.TextView[@resource-id="com.dangdang.buy2:id/tv_sure"]').click()
    # driver.find_element(AppiumBy.XPATH,
    #                     '//android.widget.TextView[@resource-id="com.dangdang.buy2:id/dialog_cancel_tv"]').click()
    driver.find_element(AppiumBy.XPATH,
                        '	//android.widget.FrameLayout[@resource-id="com.dangdang.buy2:id/home_title_layout"]/android.widget.LinearLayout').click()
    driver.find_element(AppiumBy.XPATH,
                    '//android.widget.EditText[@resource-id="com.dangdang.buy2:id/et_search"]').send_keys("浪潮之巅")
    driver.find_element(AppiumBy.XPATH,
                        '//android.widget.TextView[@resource-id="com.dangdang.buy2:id/tv_search"]').click()

    width=driver.get_window_size()['width']
    height=driver.get_window_size()['height']
    driver.swipe(width*0.5,height*0.8,width*0.5,height*0.2)
    driver.swipe(width*0.5,height*0.2,width*0.5,height*0.8)

    driver.find_element(AppiumBy.XPATH,
                        '(//android.widget.TextView[@resource-id="com.dangdang.buy2:id/add_cart_tv"])[1]').click()
    driver.find_element(AppiumBy.XPATH,
                        '//android.widget.CheckBox[@resource-id="com.dangdang.buy2:id/color_size_rb" and @text="【畅销款】浪潮之巅"]').click()
    driver.find_element(AppiumBy.XPATH,
                        '//android.widget.TextView[@resource-id="com.dangdang.buy2:id/product_select_color_size_confirm"]').click()
    driver.find_element(AppiumBy.XPATH,
                        '//android.widget.TextView[@resource-id="com.dangdang.buy2:id/etv_back"]').click()
    driver.find_element(AppiumBy.XPATH,
                        '//android.widget.TextView[@resource-id="com.dangdang.buy2:id/etv_back"]').click()
    driver.find_element(AppiumBy.XPATH,
                        '//android.widget.TabWidget[@resource-id="android:id/tabs"]/android.widget.FrameLayout[4]').click()
    driver.find_element(AppiumBy.XPATH,
                        '//android.widget.TextView[@resource-id="com.dangdang.buy2:id/cart_balance_tv"]').click()
    driver.find_element(AppiumBy.XPATH,
                        '//android.widget.TextView[@resource-id="com.dangdang.buy2:id/cart_balance_tv"]').click()




    # driver.find_element(AppiumBy.XPATH,
    #                     '//android.widget.EditText[@resource-id="com.dangdang.buy2:id/et_account"]').send_keys('18271411582')
    # driver.find_element(AppiumBy.XPATH,
    #                     '//android.widget.CheckBox[@resource-id="com.dangdang.buy2:id/chb_privacy"]').click()
    # driver.find_element(AppiumBy.XPATH,
    #                     '').click()
    # driver.find_element(AppiumBy.XPATH,
    #                     '').click()
    # driver.find_element(AppiumBy.XPATH,
    #                     '').click()
    # driver.find_element(AppiumBy.XPATH,
    #                     '').click()
    # driver.find_element(AppiumBy.XPATH,
    #                     '').click()
    # driver.find_element(AppiumBy.XPATH,
    #                     '').click()
    # driver.find_element(AppiumBy.XPATH,
    #                     '').click()
    # driver.find_element(AppiumBy.XPATH,
    #                     '').click()
    # driver.find_element(AppiumBy.XPATH,
    #                     '').click()
    # driver.find_element(AppiumBy.XPATH,
    #                     '').click()





























































